package com.zhang.crm.service.impl;

import com.zhang.crm.constant.Constants;
import com.zhang.crm.service.RedisService;
import jakarta.annotation.Resource;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;


@Service
public class RedisServiceImpl implements RedisService {
    @Resource
    private  StringRedisTemplate stringRedisTemplate;

    @Resource
    private RedisTemplate redisTemplate;

    public  void set(String key, String value){
        stringRedisTemplate.opsForValue().set(key,value);
    }

    @Override
    public Boolean expire(String key, Long time, TimeUnit timeUnit) {
       return stringRedisTemplate.expire(key, time, timeUnit);
    }

    @Override
    public String get(String key) {
        return stringRedisTemplate.opsForValue().get(key);
    }

    @Override
    public Boolean delete(String key) {
        return stringRedisTemplate.delete(key);
    }

    @Override
    public long getUniqueNum() {
        Long increment = stringRedisTemplate.opsForValue().increment(Constants.REDIS_TRAN_KEY + "TRAN");

        return increment;
    }


}
